import sim

# 连接到 CoppeliaSim 远程 API 服务器
clientID = sim.simxStart('127.0.0.1', 19999, True, True, 5000, 5)
if clientID != -1:
    print('Connected to CoppeliaSim')
else:
    print('Failed to connect to CoppeliaSim')
    exit()


# 定义物体的名称
object_name = 'Dummy'

# 获取物体的句柄
returnCode, handle = sim.simxGetObjectHandle(clientID, object_name, sim.simx_opmode_blocking)
if returnCode == sim.simx_return_ok:
    # 获取物体的位置
    returnCode, position = sim.simxGetObjectPosition(clientID, handle, -1, sim.simx_opmode_blocking)
    if returnCode == sim.simx_return_ok:
        print(f'The current position of {object_name} is: {position}')
    else:
        print('Failed to get the position of the object')
else:
    print('Failed to get the handle of the object')

# 关闭连接
sim.simxFinish(clientID)